﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LIMS.Web
{
    public partial class AdmMeassageView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                #region 还原数据，以便于管理员回复留言
                if (Request.QueryString["mesId"] != null)
                {
                    Int32 mesIDTmp = 0;
                    String strMesQuery = Request.QueryString["mesId"].ToString();
                    if (!Int32.TryParse(strMesQuery, out mesIDTmp))
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请不要非法操作!');", true);
                        return;
                    }
                    LIMS.Model.Messages message = BLL.MessageManager.GetMessageByID(strMesQuery);
                    txtMesDetail.Text = message.mesDetail;
                    txtStuName.Text = BLL.MessageManager.GetStuNameByMesID(strMesQuery);
                    txtStuName.ReadOnly = true;
                    txtMesTitle.Text = message.mesTitle;
                    txtReview.Text = message.mesReply;
                } 
                #endregion
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["mesId"] != null)
            {
                Int32 mesIDTmp = 0;
                String strMesQuery = Request.QueryString["mesId"].ToString();
                if (!Int32.TryParse(strMesQuery, out mesIDTmp))
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请不要非法操作!');", true);
                    return;
                }
                if (Session["adminID"] != null && !String.IsNullOrWhiteSpace(Session["adminID"].ToString()))
                {
                    Model.Messages message = new Model.Messages()
                    {
                        mesID = strMesQuery,
                        mesReply = txtReview.Text.Trim(),
                        mesAdminID = Session["adminID"].ToString()
                    };
                    BLL.MessageManager.ReplyMessage(message);
                    this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('留言回复成功!');window.location.href='AdmMeassageView.aspx';", true);
                }
            }
        }




    }
}